<?php

namespace app\admin\controller;

use app\common\controller\AdminBase;
use think\facade\Db;

class DataTagAttr extends AdminBase
{
    public function index()
    {
        $list = Db::name('data_tag_attr')->select()->toArray();
        return view('',['list'=>$list]);
    }

    public function add()
    {
        if( $this->request->isPost() ) {
            $param = $this->request->param();
            $result = Db::name('data_tag_attr')->insert($param);
            if( $result ) {
                xn_add_admin_log('添加属性');
                $this->success('操作成功');
            } else {
                $this->error('操作失败');
            }
        }
        return view('form');
    }

    public function edit()
    {
        if( $this->request->isPost() ) {
            $param = $this->request->param();
            $result = Db::name('data_tag_attr')->update($param);
            if( $result ) {
                xn_add_admin_log('修改属性');
                $this->success('操作成功');
            } else {
                $this->error('操作失败');
            }
        }

        $id = $this->request->get('id');
        $data = Db::name('data_tag_attr')->find($id);
        return view('form',['data'=>$data]);
    }

    public function delete()
    {
        $id = intval($this->request->get('id'));
        !($id>0) && $this->error('参数错误');
        Db::name('data_tag_attr')->delete($id);
        xn_add_admin_log('删除属性');
        $this->success('删除成功');
    }
}
